#ifndef STORAGE_H
#define STORAGE_H

#include <QtCore>

class Storage : public QThread
{
    Q_OBJECT
public:
    Storage();
    ~Storage();
    void setStorage(int type); //1==zip, 2==oss
    void setRootPath(const QString &filePath);
    void watchPath(const QString &filePath);
    void updateFiles();

private slots:
    void onInit();
    void onWatchPaths(const QFileInfoList &dirs);
    void onUpdateFiles();

    void onFileChanged(const QString &path);
    void onDirectoryChanged(const QString &path);

private:
    QFileInfoList getAllFiles(const QString &filePath);
    QFileInfoList getFiles(const QString &filePath);
    QFileInfoList getAllDirs(const QString &filePath);
    QString writeToZipFile(const QFileInfoList &files);
    bool saveToOssServer(const QFileInfoList &files);

private:
    std::string oss_key_;
    std::string oss_secret_;
    std::string oss_endpoint_;
    std::string oss_bucket_;
    QString zipStoragePath_;

    int type_ = 0;

    QString gitRootPath_;
    QString gitRootFilePath_;

    QSharedPointer<QFileSystemWatcher> watcher_;
    QSet<QString> watches_;
    QHash<QString, QDateTime> lastModified_;
    QSet<QString> changes_;
};

#endif // STORAGE_H
